package net.hn.hnms.biz.energy.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.domain.ElectricityPlacePrice;
import net.hn.hnms.biz.energy.request.ElectricityPlacePriceReq;
import net.hn.hnms.biz.energy.service.ElectricityPlacePriceService;
import net.hn.hnms.biz.energy.vo.ElectricityPlacePriceVo1;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.log.annotation.Log;
import net.hn.hnms.sys.common.log.enums.BusinessType;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "用电地点电单价设置", tags = {"用电地点电单价设置"})
@RestController
@RequestMapping("/electricity/place/price")
public class ElectricityPlacePriceController extends BaseController {
    @Autowired
    private ElectricityPlacePriceService electricityPlacePriceService;


    /**
     * 新增用电地点电单价设置
     */
    @ApiOperation("新增用电地点电单价设置")
    @SaCheckPermission("electricity:place:add")
    @PostMapping("/add")
    @Log(title = "新增用电地点电单价设置", businessType = BusinessType.INSERT)
    public R<Void> add(@Validated @RequestBody ElectricityPlacePriceReq electricityPlacePriceReq) {
        return toAjax(electricityPlacePriceService.insert(electricityPlacePriceReq));
    }

    /**
     * 删除用电地点电单价设置
     */
    @ApiOperation("删除用电地点电单价设置")
    @SaCheckPermission("electricity:place:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @PostMapping("delete")
    @Log(title = "删除用电地点电单价设置", businessType = BusinessType.DELETE)
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        electricityPlacePriceService.updateDeleteByIds(idList);
        return R.ok();
    }

    /**
     * 更新用电地点电单价设置
     */
    @ApiOperation("更新用电地点电单价设置")
    @SaCheckPermission("electricity:place:update")
    @PostMapping("/update")
    @Log(title = "更新用电地点电单价设置", businessType = BusinessType.UPDATE)
    public R<Void> update(@Validated @RequestBody ElectricityPlacePriceReq electricityPlacePriceReq) {
        electricityPlacePriceService.updateById(electricityPlacePriceReq);
        return R.ok();
    }

    /**
     * 用电地点电单价设置详情
     */
    @ApiOperation("获取供水台账详情")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/{id}")
    public R<ElectricityPlacePrice> detail(@PathVariable("id") String id) {
        return R.ok(electricityPlacePriceService.selectDetailById(id));
    }

    /**
     * 用电地点电单价设置列表
     */
    @ApiOperation("电负荷单价设置列表")
//    @SaCheckPermission("plan:drivage:page")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<ElectricityPlacePriceVo1>> page(ElectricityPlacePriceReq electricityPlacePriceReq, PageQuery pageQuery) {
        return R.ok(electricityPlacePriceService.selectPageList(electricityPlacePriceReq, pageQuery));
    }

    /**
     * 用电地点电单价设置列表
     */
    @ApiOperation("负荷名称下拉列表")
//    @SaCheckPermission("plan:mining:list")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<ElectricityPlacePrice>> list(ElectricityPlacePriceReq electricityPlacePriceReq) {
        return R.ok(electricityPlacePriceService.selectList(electricityPlacePriceReq));
    }


}
